<template>
  <el-dialog title="角色列表" :visible="isShowAssign" @close="btnCancel">
    <el-checkbox-group v-model="checkList">
      <el-checkbox
        v-for="role in roleList"
        :key="role.id"
        :label="role.id"
      >
        {{ role.name }}
      </el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <el-row type="flex" justify="center">
        <el-button size="small" type="primary" @click="btnOk">确定</el-button>
        <el-button size="small" @click="btnCancel">取消</el-button>
      </el-row>
    </template>
  </el-dialog>
</template>

<script>
import { getRoleList } from '@/api/setting'
import { getEmployeeInfo, assignRoles } from '@/api/employee'
export default {
  props: {
    isShowAssign: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      roleList: [],
      checkList: [],
      id: ''
    }
  },
  async created() {
    await this.getRoleList()
  },
  methods: {
    async getRoleList() {
      console.log(122344)
      const { rows } = await getRoleList(999)
      this.roleList = rows
      console.log(this.roleList, 37)
    },
    btnCancel() {
      this.checkList = []
      this.$emit('update:isShowAssign', false)
    },
    async getEmployeeInfo(id) {
      const { roleIds } = await getEmployeeInfo(id)
      this.checkList = roleIds
      console.log(55, id)
      this.id = id
    },
    async btnOk() {
      await assignRoles({ id: this.id, roleIds: this.checkList })
      this.$message.success('修改员工角色信息成功!')
      this.$emit('update:isShowAssign', false)
    }
  }
}
</script>

<style>

</style>
